package com.jn.dagger.views;

import android.util.Log;
import android.widget.TextView;

import com.jn.dagger.R;
import com.jn.dagger.application.MyApplication;
import com.jn.dagger.base.BaseActivity;
import com.jn.dagger.database.CourseDBHelper;
import com.jn.dagger.database.DBHelper;
import com.jn.dagger.entity.Course;
import com.jn.dagger.entity.Student;
import com.jn.dagger.module.DBModule;
import com.jn.dagger.module.StudentModule;
import com.jn.dagger.utils.SpUtils;

import java.util.List;

import jakarta.inject.Inject;

public class InfoActivity extends BaseActivity {
    @Inject
    public Student mStudent;
    @Inject
    public DBHelper mDBHelper;

    @Inject
    public Course mCourse ;
    @Inject
    public CourseDBHelper courseDBHelper ;

    private TextView sSize , cSize ;
    @Override
    public int getLayoutId() {
        return R.layout.activity_info;
    }

    @Override
    public void init() {
        sSize = findViewById(R.id.s_size);
        cSize = findViewById(R.id.c_size);

        /*DaggerAllComponent
                .builder()
                .studentModule(new StudentModule())
                .dBModule(new DBModule(this))
                .build()
                .injectInfoActivity(this);*/
        ((MyApplication)getApplication()).getAllComponent().injectInfoActivity(this);
        Log.d("asdf", "Info mStudent === " + mStudent.hashCode());
        List<Student> list = mDBHelper.selectAllStudent();
        int size = list.size();
        Log.d("asdf", "Info mDBHelper === " + mDBHelper.hashCode());
        mStudent = mDBHelper.selectAllStudent().get(size - 1);
        //Log.d("asdf", "Info mStudent === " + mStudent.hashCode());
        Log.d("asdf", mStudent.toString());

        List<Course> courseList = courseDBHelper.selectAllCourse();
        int size1 = courseList.size();
        mCourse = courseDBHelper.selectAllCourse().get(size1 -1);
        Log.d("info-course@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", mCourse.toString());

        List<Student> students = SpUtils.getInstance(this).getList("students");
        Student student1 = students.get(students.size()-1) ;
        Log.d("SpUtils方法查询数据", student1.toString());

        sSize.setText("学生数量：" + size + "\n" + "size-1学生姓名：" + mStudent.getStudent_name());
        cSize.setText("班级数量：" + size1 + "\n" + "size-1班级名称：" + mCourse.getCourse_name() + "\n" +
                "使用SpUtils方法获取到的学生列表：\n" + students.get(students.size()-1).getStudent_name() + "," +
                String.valueOf(students.get(students.size()-1).getStudent_id()));
    }
}
